<template>
    <div style="background-color: #fff;width:100%">
        <main class="search-page__main">
            <div>
                <div class="search-title">
                    名称 或 个人介绍中包含
                    <span class="search__word">{{searchText}}</span> 的作者
                </div>
                <div loading-insert-type="embed" loading-type="tips"
                     style="position: relative;">
                    <article class="author-cell"  v-for="(author,index) in authors" :key="index">
                        <section  class="stage-flex-container"
                                 style="justify-content: flex-start; align-items: stretch; align-self: auto; flex: 1 1 0%;">
                            <a href="" target="_self">
                                <div class="avatar-wrapper hoverable is-round"
                                     style="flex: 0 0 64px; width: 64px; height: 64px; margin-right: 15px; padding-bottom: 0px;">
                                    <section class="avatar-wrapper__img-wrapper"
                                             style="width: 64px; height: 64px; background: rgb(255, 255, 255);">
                                        <img :src="imgUrl+author.authorImg"
                                             class="avatar-wrapper__avatar border"
                                             style="width: 64px; height: 64px; border-color: rgb(236, 236, 236);"
                                        @click="gotoUser(author)">
                                    </section>
                                </div>
                            </a>
                            <section class="author-cell__infos-wrapper">
                                <section class="author-cell__infos-info-wrapper">
                                    <section class="stage-flex-container"
                                             style="justify-content: flex-start; align-items: stretch; align-self: stretch;">
                                        <section class="stage-flex-container"
                                                 style="justify-content: flex-start; align-items: center; align-self: auto; flex: 1 1 0%; width: 0px;">

                                        </section>
                                    </section>
                                    <section class="author-cell__comment-schedule-wrapper">
                                        <section class="author-cell__comment-info stage-flex-container"
                                                 style="justify-content: flex-start; align-items: center; align-self: auto;">
                                            <span><a href="" class="author-cell__name" target="_self">
                                                {{author.username}}
                                            </a></span>
                                        </section>
                                    </section>
                                </section>
<!--                                <button type="button"-->
<!--                                        class="stage-button author-cell__approximate-button stage-button&#45;&#45;primary stage-button&#45;&#45;medium">-->
<!--                                    <span>邀请</span>-->
<!--                                </button>-->
                            </section>
                        </section>
                        <section class="author-cell__artworks">
                            <div v-for="(work,index) in author.worksInfos" :key="index" v-if="index < 5" class="author-cell__artwork-wrapper stage-img">
                                <div  v-if="work.workFileType === 1"
                                      class="author-cell__artwork-wrapper stage-imgstage-img__hover-shade"
                                      @click="workDetail(work)">
                                    <img class="stage-img__img is-hoverable is-bordered is-responsive" lazy="loaded" style="border-color: rgb(236, 236, 236); border-radius: 4px;" :src="imgUrl+work.workFilename"/>
                                </div>
                                <div @click="workDetail(work)" v-else class="author-cell__artwork-wrapper stage-imgstage-img__hover-shade">

                                            <video :poster="work.poster" :controls="true" class="stage-img__img is-hoverable is-bordered is-responsive"
                                                   :src="imgUrl+work.workFilename"></video>

                                </div>
                            </div>


                        </section>
                    </article>



                </div>
                <!--页码-->
                <section class="stage-flex-container"
                         style="justify-content: center; align-items: stretch; align-self: auto;">
                    <div class="is-darken el-pagination is-background">
                        <el-pagination
                                background
                                layout="prev, pager, next"
                                :total="authors.length">
                        </el-pagination>
                    </div>
                </section>
            </div>
        </main>
    </div>
</template>

<script setup>
  import {getAuthorsByKeyword} from "@/assets/api/authorApi";
  import {addWorkComment, getWorkComment, getWorkInfoById} from "@/assets/api/workInfoApi";
  import {useRoute, useRouter} from "vue-router";
  import {getCurrentInstance, onBeforeMount, ref} from "vue";

  const imgUrl = getCurrentInstance()?.appContext.config.globalProperties.$imgUrl
  const router = useRouter();
  const route = useRoute();
  const searchText = ref(route.query.searchText);
  const authors = ref([{}]);
  const user = ref([{}]);
  const workInfo = ref({});


  const getAuthors = () => {
    searchText.value = route.query.searchText;
    let data = {};
    data.username = searchText.value;
    getAuthorsByKeyword(data).then((res) => {
      authors.value = res.data.data;
    });
  };
  const gotoUser = (user) => {
    router.push({path: '/authorPage', query: {id: user.userId}});
  };
  const workDetail = (work) => {
    router.push({path: '/workDetail', query: {id: work.workId}});
  };

  // watch({
  //     '$route' (to, from){
  //         getAuthors();
  //     }
  // })
  onBeforeMount(() => {
    getAuthors();
  });
</script>

<style scoped>


    .search-page__main {
        margin-top: 30px;
        margin-left: 12%;
        width: 1200px;
    }

    .search-title {
        display: block;
        font-size: 1.5em;
        margin-block-start: 0.83em;
        margin-block-end: 0.83em;
        margin-inline-start: 0px;
        margin-inline-end: 0px;
        font-weight: bold;
        margin-bottom: 5px;
    }

    .search__word {
        color: #adb3fb;
        font-weight: 700;
    }

    .author-cell {
        background: #fff;
        padding: 30px 0;
        display: flex;
        align-items: flex-start;
    }

    .stage-flex-container {
        display: flex;
    }

    .avatar-wrapper {
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        transition: .5s;
        box-sizing: content-box;
    }

    .avatar-wrapper.is-round .avatar-wrapper__img-wrapper, .avatar-wrapper.is-round img {
        border-radius: 100%;
    }

    .avatar-wrapper__img-wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
    }

    .avatar-wrapper__avatar.border {
        border: 1px solid transparent;
    }

    .avatar-wrapper__avatar {
        width: 100%;
        opacity: 1;
    }

    .border {
        border-width: 1px;
    }

    .author-cell__infos-info-wrapper, .author-cell__infos-wrapper {
        display: flex;
        flex-direction: column;
    }

    .author-cell__infos-wrapper {
        width: 0;
        flex: 1;
        align-items: flex-start;
        margin-right: 15px;
    }

    .author-cell__name {
        font-size: 16px;
        font-weight: 500;
        margin-right: 5px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: #707070;
        transition: .5s;
        cursor: pointer;
    }

    .author-badges.is-show {
        display: inline-flex;
    }

    .author-badges {
        display: none;
        align-items: center;
        justify-content: flex-start;
    }

    .author-cell__comment-info {
        font-size: 12px;
        color: #adb3fb;
        margin-top: 5px;
    }

    .author-cell__approximate-button {
        margin-top: 10px;
    }

    .stage-button--primary {
        color: #fff;
        background-color: #00a8e9;
        border-color: #00a8e9;
    }

    .stage-button--medium {
        padding: 10px 24px;
        font-size: 14px;
        border-radius: 4px;
    }

    .stage-button {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        border: 1px solid #dcdfe6;
        appearance: none;
        text-align: center;
        outline: none;
        transition: .1s;
        user-select: none;
        padding: 10px 24px;
        font-size: 14px;
        border-radius: 4px;
    }

    .author-cell__artworks {
        display: grid;
        gap: 15px;
        grid-template-columns: repeat(5, 178px);
    }

    .author-cell__artwork-wrapper {
        display: flex;
        flex: 1;
        align-items: center;
        justify-content: center;
    }

    .stage-img {
        position: relative;
    }

    .stage-img__hover-shade {
        opacity: 0;
        pointer-events: none;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        background: #fff;
        background: hsla(0, 0%, 100%, .2);
        transition: .5s;
    }

    img[lazy=loaded] {
        animation: fadeIn-data-v-3dd27e86 .8s;
    }

    .stage-img__img.is-hoverable {
        cursor: pointer;
    }

    .stage-img__img.is-bordered {
        border: 1px solid transparent;
    }

    .stage-img__img.is-responsive {
        width: 178px;
        display: flex;
        flex: none;
        height: 178px;
    }

    .stage-img__img {
        display: block;
    }




    /deep/ .el-dialog {
        display: flex;
        flex: 1;
        background-color: transparent;
        box-shadow: unset;
        position: static;
        width: auto;
        border-radius: 4px;
    }

    /deep/ .el-dialog__header {
        padding: 30px 30px 10px;
    }

    /deep/ .el-dialog__body {
        justify-content: center;
        align-items: center;
        display: flex;
        flex: 1;
        padding: 20px 30px 30px;
        color: #4a4a4a;
        font-size: 14px;
        word-break: break-all;
    }

    .dialog {
        z-index: 1000;
    }

    .artwork-modal__modal {
        position: relative;
        width: 950px;
        height: auto;
        border-radius: 8px;
        margin: auto;
    }

    .modal-author {
        padding: 20px 30px;
        margin-bottom: 20px;
        border-radius: 4px;
        background: #fff;
        display: flex;
        justify-content: space-between;
    }

    .stage-flex-container {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
    }

    .avatar-wrapper {
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        transition: .5s;
        box-sizing: content-box;
    }

    .avatar-wrapper__img-wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
    }

    .avatar-wrapper.is-round .avatar-wrapper__img-wrapper, .avatar-wrapper.is-round img {
        border-radius: 100%;
    }

    .avatar-wrapper__avatar.border {
        border: 1px solid transparent;
    }

    .avatar-wrapper__avatar {
        width: 100%;
        opacity: 1;
    }

    .modal-author__author-info {
        display: flex;
        width: auto;
        flex: 0 0 auto;
        flex-direction: column;
        justify-content: center;
        color: #707070;
    }

    .modal-author__author-credit {
        margin-top: 5px;
        display: inline-block;
    }

    .el-rate {
        height: 20px;
        line-height: 1;
    }

    .el-rate__item {
        font-size: 0;
        vertical-align: middle;
    }

    .stage-flex-container {
        display: flex;
    }

    .modal-author__author-operator button {
        margin-left: 15px;
        width: 94px;
        height: 30px;
        padding: 4px 15px;
        border-radius: 20px;
        border: 1px solid transparent;
    }

    .stage-button--warning {
        color: #fff;
        background-color: #adb3fb;
        border-color: #9eb0fb;
    }

    .stage-button--small {
        padding: 7px 18px;
        font-size: 12px;
        border-radius: 4px;
    }

    .stage-button {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        border: 1px solid #dcdfe6;
        appearance: none;
        text-align: center;
        outline: none;
        margin: 0;
        transition: .1s;
        user-select: none;
        padding: 10px 24px;
        font-size: 14px;
        border-radius: 4px;
    }

    a {
        text-decoration: none;
    }
    .video_fo {
        position: relative;
        width: 283px;
        height: 200px;
        left: 20px;
    }

    .stage-img {
        position: relative;
    }

    .artwork-modal__artwork-img-wrapper img {
        width: 100%;
        cursor: pointer;
        border-top-left-radius: 4px;
    }
    .stage-img__img.is-hoverable {
        cursor: pointer;
    }

    .stage-img__img.is-responsive {
        max-width: 100%;
        display: flex;
        flex: none;
        margin: 0 auto;
        width: 950px;
    }
    .stage-img__img {
        display: block;
    }
    .stage-flex-container {
        display: flex;
    }
</style>
